import mongoose from '../dbHelper';
import { defaultSchemaExtend, defaultSchemaOptions } from "../config/index";

const Schema = mongoose.Schema;

const ShopSchema = new Schema(Object.assign({
    access_token: String,
    auth_subject_type: String,
    authority_id: String,
    encrypt_operator: String,
    expires_in: Number,
    operator_name: String,
    refresh_token: String,
    scope: String,
    shop_id: Number,
    shop_name: String,
    service_start_time: Number,
    service_end_time: Number,
    access_token_update_time: Number,
    action_type: {
        type: Number,
        default: 1 // 1关闭授权, 2打开授权, 3授权过期, 4重新获取授权码
    },
    user_phone: String, // 用户自行填写的手机号
    shop_phone: String, // 店铺绑定的手机号
    proxyId: {
        type: Schema.Types.ObjectId,
        ref: 'DlyAdminUser' // 代理商id
    }, // 代理商id
    proxyLinkId: {
        type: Schema.Types.ObjectId,
        ref: 'DlyAdminLink' // 代理商下级id
    },
    proxyStateTime: Date, // 代理商下级状态时间
    isBuy: {
        type: Number,
        default: 0 // 0未购买, 1已购买付费，2订购试用，3订购过期，4退款成功
    },
    openForBusinessTime: { // 开业时间
        type: String,
    },
    // 订购到期时间
    expireTime: {
        type: String
    },
    // 赠送的j积分点 随着订单的增加而增加 查询 优先扣除这里的积分
    // 需要判断是否订单过去， 过期后不可使用店铺积分
    aiRemainScore: {
        type: Number,
        default: 0
    },
    jianceScore: Number,
    jianceSendScore: Number,
    // 绑定对应的用户账号
    aiUserId: {
        type: Schema.Types.ObjectId,
        ref: 'AiUser'
    },
    dlyUserId: {
        type: Schema.Types.ObjectId,
        ref: 'AiUser'
    },
    bindAiuserTime: {
        type: Date
    },
    channelCode: {
        type: String
    },
    sendEditNum: {
        type: Number,
        default: 50
    },
    useEditNum: {
        type: Number,
        default: 0
    }
}, defaultSchemaExtend), defaultSchemaOptions);

const Shop = mongoose.model('Shop', ShopSchema, 'Shops');

export default Shop